/**
 * Foxit Software Inc.
 * Copyright(C) 2005-2014, all rights reserved.
 * The following code is copyrighted and contains proprietary information
 * and trade secrets of Foxit Software Inc.

 * Description: Ink annotation
 * Author: shaojie zhuo
 */
define(function (require, exports, module) {
    var PDFAnnot = require('./Annot.js');
    var PDFMarkupAnnot = WebPDF.PDFData.PDFMarkupAnnot;
    require('../Interface.js');
    var Interface = WebPDF.Interface;
    var AnnotDataJSONFormat = WebPDF.PDFData.AnnotDataJSONFormat;

    var PDFInkAnnot = function (jsonData) {
    	PDFInkAnnot.superclass.constructor.call(this, jsonData);
		this.inkList = null;
        $.extend(this,{
            /**
             * Initialize point list of current ink annotation.
             * @param {Number} offsetX offset in x-axis for all of points of current annotation.
             * @param {Number} offsetY offset in y-axis for all of points of current annotation.
             * @param {Boolean} bForce 是否强制更新Ink List, 如果offsetX 和 offsetY设置为非0， 改参数需要设置为true才能使设置生效
             * @private
             */
            _initInkList: function (offsetX, offsetY, bForce) {
                if (bForce || this.inkList == null) {
                    this.inkList = [];
                    if (this.annotJSONData[AnnotDataJSONFormat.inkList] == null) {
                        return;
                    }
                    var inkArrayCnt = this.annotJSONData[AnnotDataJSONFormat.inkList].length;
                    for(var i = 0; i < inkArrayCnt; i++)
                    {
                        var inkArrayJson = this.annotJSONData[AnnotDataJSONFormat.inkList][i];
                        var ptCount = inkArrayJson.length;
                        var inkPtArray  = [];
                        for(var j=0; j<ptCount; j+=2)  {
                        	if (offsetX) {
                        		inkArrayJson[j] += offsetX;
                        	}
                        	if (offsetY) {
                        		inkArrayJson[j+1] += offsetY;
                        	}
                            inkPtArray.push(new WebPDF.PDFPoint(inkArrayJson[j],inkArrayJson[j+1]));
                        }
                        this.inkList.push(inkPtArray);
                    }
                }
            },
            /**
             * Offset all of points of current annotation
             * @param {Number} offsetX offset in x-axis for all of points of current annotation.
             * @param {Number} offsetY offset in y-axis for all of points of current annotation.
             */
            offsetInkList: function (offsetX,offsetY) {
                this._initInkList(offsetX, offsetY, true);
            },
            /**
             * Get border width of current annotation
             * @returns {Number}
             */
            getInkBorderWidth: function(){
                return this.annotJSONData[AnnotDataJSONFormat.inkBorderWidth];
            },
            /**
             * Get color of current annotation.
             * @returns {String}
             */
            getInkColor: function(){
                return this.annotJSONData[AnnotDataJSONFormat.inkColor];
            },
            /**
             * Get point list of current annotation
             * @returns {Array.<WebPDF.PDFPoint>}
             */
            getInkList: function () {
                this._initInkList();
                return this.inkList;
            }
        });
    };
    Interface.extend(PDFInkAnnot, PDFMarkupAnnot);


    WebPDF.PDFData.PDFInkAnnot = PDFInkAnnot;
    return WebPDF.PDFData.PDFInkAnnot;
});